#include <iostream>
#include <vector>
#include <string>

using namespace std;

const int c[] = {0x80, 0xE0, 0xF0, 0xF8, 0xC0}, num[] = {0x00, 0xC0, 0xE0, 0xF0, 0x80};

bool validUtf8(vector<int>& data) {
    auto it = data.begin();
    while(it != data.end()){
        if((*it & c[0]) == num[0]){
            it++;
        }else if((*it & c[1]) == num[1]){
            if(++it == data.end() || (*it & c[4]) != num[4]) return false;
            it++;
        }else if((*it & c[2]) == num[2]){
            if(++it == data.end() || (*it & c[4]) != num[4]) return false;
            if(++it == data.end() || (*it & c[4]) != num[4]) return false;
            it++;
        }else if((*it & c[3]) == num[3]){
            if(++it == data.end() || (*it & c[4]) != num[4]) return false;
            if(++it == data.end() || (*it & c[4]) != num[4]) return false;
            if(++it == data.end() || (*it & c[4]) != num[4]) return false;
            it++;
        }else{
            return false;
        }
    }
    return true;
}

int main(){
    vector<int> data = {255};
    cout << validUtf8(data) << endl;
    return 0;
}
